<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <!-- prop: -->
      <el-table-column prop="first_cateid" label="一级分类" width="100">
      </el-table-column>
      <el-table-column prop="second_cateid" label="二级分类" width="100">
      </el-table-column>
      <el-table-column prop="goodsname" label="商品名称" width="100">
      </el-table-column>
      <el-table-column label="商品图片" width="120">
        <template slot-scope="scope">
          <img v-if="scope.row.img" :src="$host + scope.row.img" width="120" />
        </template>
      </el-table-column>
      <el-table-column prop="price" label="销售价格" width="100">
      </el-table-column>
      <el-table-column prop="market_price" label="市场价格" width="100">
      </el-table-column>
      <el-table-column label="是否新品" prop="isnew">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.isnew"
            active-color="#13ce66"
            inactive-color="#ff4949"
            @change="onOff"
          >
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="是否热卖" prop="ishot">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.ishot"
            active-color="#13ce66"
            inactive-color="#ff4949"
            @change="onOff"
          >
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态" width="150">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.status === 1">正常</el-tag>
          <el-tag type="danger" v-else>禁用</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-edit"
            @click="edit(scope.row)"
            circle
          ></el-button>
          <el-button
            size="mini"
            type="danger"
            icon="el-icon-delete"
            @click="del(scope.row.id)"
            circle
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { goodsDel, goodslist } from "../../request";
export default {
  data() {
    return {
      tableData: [],
      //   isShow: true,
      //   isDisabled: true,
      // value1:'',
      // value2:'',
    };
  },
  created() {
    this.getList();
    this.$bus.$on("update", () => {
      this.getList();
    });
  },
  methods: {
    //需要先获取总数量，才能计算分成多少页，然后查看某一页
    async getList() {
      let res = await goodslist();
      this.tableData = res.list;
    },
    //开关按钮
    onOff() {},
    // 编辑
    edit(info) {
      console.log(info);
      this.$emit("edit", { ...info });
    },
    //删除菜单弹窗
    del(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })

        //点击确定
        .then(() => {
          this.goodsDel(id);
        })
        //点击取消
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //真的要删了
    async goodsDel(id) {
      let res = await goodsDel(id);
      this.tableData = res.list;
    },
    // 切换页码时调用
    // handleCurrentChange(val) {
    //   this.getUserList();
    // },
    check(id) {
      this.dialogVisible = true;
    },
  },
};
</script>

<style>
</style>